package com.aigua.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 统一结果集
 * @TODO:
 * @Author:baimu
 * @Date:2024 04 01 09 39
 **/

@AllArgsConstructor
@NoArgsConstructor
@Data
@ToString
public class CommonResult {



    private static final Integer SUCCESS_CODE = 1;
    private static final Integer ERROR_CODE = 0;

    private static final String  ERROR_MESSAGE = "ERROR";
    private static final String  SUCCESS_MESSAGE = "SUCCESS";

    /**
     * 业务状态码 0（失败），1（成功）
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String message;

    /**
     * 返回数据
     */
    private Object data;

    /**
     * 魔法值：在程序里面写死的值
     * @param code
     * @param message
     */
    public CommonResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static CommonResult success(Object data) {
        return new CommonResult(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static CommonResult success(String message, Object data) {
        return new CommonResult(SUCCESS_CODE, message, data);
    }

    public static CommonResult success(String message) {
        return new CommonResult(SUCCESS_CODE, message, null);
    }

    public static CommonResult fail( String message) {
        return new CommonResult(ERROR_CODE, message, null);
    }

    public static CommonResult fail( ) {
        return new CommonResult(ERROR_CODE, ERROR_MESSAGE);
    }

    public static CommonResult fail(String message, Object data) {
        return new CommonResult(ERROR_CODE, message, data);
    }
}
